--
-- Author: shunguo.chen
-- Date: 2018-08-14 14:09:32
--
-- LoadingView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.LoadingScene

function ClassRef:init()
	self._loadingBar = self._ui["Loading/LoadingBar"]

	self._bg = self._ui["bg/bg"]
	local bgWidth = self._bg:getContentSize().width
	local scale =  display.width / bgWidth
	self._bg:setScale(scale)

	self:setProgress(0)
	
	self._ui.Note_1:setString(L("ProgressNotCostCellularData"))

	self:hideLoadingVisible() -- 提审状态  
end

function ClassRef:setBg(imgPath)
	self._imgPath = imgPath
	local defaultFormat = cc.Texture2D:getDefaultAlphaPixelFormat()
	cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2D_PIXEL_FORMAT_RGB565)
	self._bg:loadTexture(imgPath)
	cc.Texture2D:setDefaultAlphaPixelFormat(defaultFormat)
end

function ClassRef:setTips(tips)
	local newTips = tips
	self._ui.Note:setString(newTips)
end

function ClassRef:setProgress(pg)
	self._loadingBar:setPercent(pg)
end

function ClassRef:onEnter()
	AM.playById(9023)
end

function ClassRef:onExit()
	if self._imgPath then
		display.removeSpriteFrameByImageName(self._imgPath)
		self._imgPath = nil
	end
end

function ClassRef:hideLoadingVisible()
	if app.channelAPI:isReview()  then
		self._ui["Loading"]:setVisible(false)
		self._ui.Note_1:setVisible(false)
	end
end

return ClassRef
